/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Server.domain;

/**
 *
 * @author Ripper
 */
public class PlayerLevelCalculator 
{
    public static int getLevelForExp(long xp)
    {
        int level = 0;
        
        long thisLevelExperience = 0;
        
        do
        {
            level++;
            thisLevelExperience = getExperienceForLevel(level);
        }
        while(thisLevelExperience < xp);
        
        return level - 1;
    }
    
    public static long getExperienceForLevel(int lvl)
    {
        double a = (double)250/(double)3;
        double b = -250;
        double c = (double)3500/(double)3;
        double d = -1000;
        
        double A = (a * Math.pow((double)lvl, (double)3));
        double B = (b * Math.pow(lvl, 2));
        double C = (c * Math.pow(lvl, 1));
        double D = d;
        return (long)(A + B + C + D);
    }
}
